/*
 * GraphicalPanel.java
 *
 * Created on Dec 9, 2008, 11:43:45 PM
 */
package view.panels.graphical;

import jgf.Attribute;
import jgf.beans.ArcBean;
import jgf.beans.GraphBean;
import jgf.beans.NodeBean;
import view.panels.JGSPanel;
import java.awt.Point;

/**
 *
 * @author Marcos Garcia Ortega <a href="mailto:thiamath@gmail.com">&lt;thiamath@gmail.com&gt;</a>
 */
public class GraphicalPanel extends JGSPanel {
	
	public GraphicalPanel() {
		this("");
	}

	public GraphicalPanel(String title) {
		super(title);
		this.mode = GraphicalPanel.INNOCENT_MODE;
		this.initComponents();
	}
	 
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        graphicalToolbar = new javax.swing.JToolBar();
        gpInnocentMode = new javax.swing.JToggleButton();
        gpNodesMode = new javax.swing.JToggleButton();
        gpArcsMode = new javax.swing.JToggleButton();
        gpEraserMode = new javax.swing.JToggleButton();
        scrollCanvas = new javax.swing.JScrollPane();
        canvas = new view.panels.graphical.GraphCanvas();

        setLayout(new java.awt.BorderLayout());

        graphicalToolbar.setFloatable(false);
        graphicalToolbar.setRollover(true);

        gpInnocentMode.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/Arrow30x.png"))); // NOI18N
        gpInnocentMode.setSelected(true);
        gpInnocentMode.setText("Innocent Mode");
        gpInnocentMode.setToolTipText("Innocent Mode");
        gpInnocentMode.setFocusable(false);
        gpInnocentMode.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        gpInnocentMode.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        gpInnocentMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gpInnocentModeActionPerformed(evt);
            }
        });
        graphicalToolbar.add(gpInnocentMode);

        gpNodesMode.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/Node30x.png"))); // NOI18N
        gpNodesMode.setText("Manage nodes");
        gpNodesMode.setToolTipText("Manage nodes");
        gpNodesMode.setFocusable(false);
        gpNodesMode.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        gpNodesMode.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        gpNodesMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gpNodesModeActionPerformed(evt);
            }
        });
        graphicalToolbar.add(gpNodesMode);

        gpArcsMode.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/Arc30x.png"))); // NOI18N
        gpArcsMode.setText("Manage arcs");
        gpArcsMode.setToolTipText("Manage arcs");
        gpArcsMode.setFocusable(false);
        gpArcsMode.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        gpArcsMode.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        gpArcsMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gpArcsModeActionPerformed(evt);
            }
        });
        graphicalToolbar.add(gpArcsMode);

        gpEraserMode.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/Erase30x.png"))); // NOI18N
        gpEraserMode.setText("Eraser Mode");
        gpEraserMode.setFocusable(false);
        gpEraserMode.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        gpEraserMode.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        gpEraserMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gpEraserModeActionPerformed(evt);
            }
        });
        graphicalToolbar.add(gpEraserMode);

        add(graphicalToolbar, java.awt.BorderLayout.PAGE_START);

        scrollCanvas.setViewportView(canvas);

        add(scrollCanvas, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

	private Point lastClickCoords;

	private void gpInnocentModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gpInnocentModeActionPerformed

			this.toInnocentMode();

}//GEN-LAST:event_gpInnocentModeActionPerformed

	private void gpNodesModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gpNodesModeActionPerformed

			this.toNodesMode();

}//GEN-LAST:event_gpNodesModeActionPerformed

	private void gpArcsModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gpArcsModeActionPerformed
	
			this.toArcsMode();

}//GEN-LAST:event_gpArcsModeActionPerformed

	private void gpEraserModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gpEraserModeActionPerformed
	
			this.toEraserMode();

}//GEN-LAST:event_gpEraserModeActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private view.panels.graphical.GraphCanvas canvas;
    private javax.swing.JToggleButton gpArcsMode;
    private javax.swing.JToggleButton gpEraserMode;
    private javax.swing.JToggleButton gpInnocentMode;
    private javax.swing.JToggleButton gpNodesMode;
    private javax.swing.JToolBar graphicalToolbar;
    private javax.swing.JScrollPane scrollCanvas;
    // End of variables declaration//GEN-END:variables

	/////////////////////////
	// MODE CHANGE METHODS //
	/////////////////////////

	private int mode; // To identify the mode of the panel

	static final int INNOCENT_MODE = 0;
	static final int MANAGE_NODES = 1;
	static final int MANAGE_ARCS = 2;
	static final int ERASER_MODE = 3;


	public void toInnocentMode() {
		this.mode = GraphicalPanel.INNOCENT_MODE;
		this.updateToolbar();
	}

	public void toNodesMode() {
		this.mode = GraphicalPanel.MANAGE_NODES;
		this.updateToolbar();
	}

	public void toArcsMode() {
		this.mode = GraphicalPanel.MANAGE_ARCS;
		this.updateToolbar();
	}

	public void toEraserMode() {
		this.mode = GraphicalPanel.ERASER_MODE;
		this.updateToolbar();
	}

	private void updateToolbar(){		
		switch(mode){
			case GraphicalPanel.INNOCENT_MODE:
				this.gpInnocentMode.setSelected(true);
				this.gpNodesMode.setSelected(false);
				this.gpArcsMode.setSelected(false);
				this.gpEraserMode.setSelected(false);
				break;
			case GraphicalPanel.MANAGE_NODES:
				this.gpInnocentMode.setSelected(false);
				this.gpNodesMode.setSelected(true);
				this.gpArcsMode.setSelected(false);
				this.gpEraserMode.setSelected(false);
				break;
			case GraphicalPanel.MANAGE_ARCS:
				this.gpInnocentMode.setSelected(false);
				this.gpNodesMode.setSelected(false);
				this.gpArcsMode.setSelected(true);
				this.gpEraserMode.setSelected(false);
				break;
			case GraphicalPanel.ERASER_MODE:
				this.gpInnocentMode.setSelected(false);
				this.gpNodesMode.setSelected(false);
				this.gpArcsMode.setSelected(false);
				this.gpEraserMode.setSelected(true);
				break;
		}
		 
	}

	public int getMode() {
		return mode;
	}

	// <editor-fold defaultstate="collapsed" desc="JGSObserver Interface Implementation">

	public void loadGraph(GraphBean graph) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void insertNode(NodeBean node) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void deleteNode(NodeBean node) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void updateNode(NodeBean node) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void setSource(NodeBean node) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void unsetSource(NodeBean node) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void setSink(NodeBean node) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void unsetSink(NodeBean node) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void insertArc(ArcBean arc) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void deleteArc(ArcBean arc) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void updateArc(ArcBean arc) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void addDefaultNodeAttribute(Attribute attribute) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void removeDefaultNodeAttribute(Attribute attribute) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void updateDefaultNodeAttribute(String previousName, Attribute newValue) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void addDefaultArcAttribute(Attribute attribute) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void removeDefaultArcAttribute(Attribute attribute) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void updateDefaultArcAttribute(String previousName, Attribute newValue) {
		throw new UnsupportedOperationException("Not supported yet.");
	}
	
	// </editor-fold>
}
